/**  
 * All rights Reserved, Designed By Android_Robot   
 * @Title:  EquipAddActivity.java   
 * @Package com.jiyi.activity.owner   
 * @Description:    TODO(用一句话描述该文件做什么)   
 * @author: HYM     
 * @date:   2017-9-8 下午2:16:08   
 * @version V1.0     
 */
package com.jiyi.activity.new_maintenance;

import android.app.Dialog;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;

import com.android.volley.VolleyError;
import com.bumptech.glide.Glide;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.animation.GlideAnimation;
import com.bumptech.glide.request.target.SimpleTarget;
import com.bumptech.glide.request.target.Target;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import com.jiyi.adapter.CommonAdapter;
import com.jiyi.adapter.ViewHolder;
import com.jiyi.bean.maintenance.EquipSystemBean;
import com.jiyi.bean.maintenance.SystemEquipItemBean;
import com.jiyi.bean.owner.BuildEquipBean;
import com.jiyi.bean.owner.FloorBean;
import com.jiyi.bean.owner.PlanBean;
import com.jiyi.bean.owner.PlanBean.PlanEquip;
import com.jiyi.bean.weibao.CsszLcInfoBean.EquipType;
import com.jiyi.common.StringInterface;
import com.jiyi.common.VolleyRequest;
import com.jiyi.easemob.util.UserHelp;
import com.jiyi.inteface.PhotoClickInterface;
import com.jiyi.inteface.WebApi;
import com.jiyi.widget.CanTouchImageView;
import com.swift.base.ActivityBase;
import com.swift.maintenance.R;
import com.swift.maintenance.base.AppBase;
import com.swift.maintenance.base.AppConfig;
import com.swift.maintenance.utils.CheckUtil;
import com.swift.maintenance.utils.ToastUtil;
import com.swift.maintenance.utils.UserInfoUtil;
import com.swift.utils.DeviceUtil;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @ClassName: EquipAddActivity
 * @Description:TODO(新增设备)
 * @author: HYM
 * @date: 2017-9-8 下午2:16:08
 * 
 */
public class EquipAddActivity extends ActivityBase {

	/* 头部 */
	@BindView(R.id.tvBack)
	TextView tvBack;
	@BindView(R.id.tvTitle)
	TextView tvTitle;
	@BindView(R.id.tvSearch)
	TextView tvSearch;

	@BindView(R.id.ivPic)
	CanTouchImageView ivPic;
	@BindView(R.id.rlPoint)
	RelativeLayout rlPoint;
	@BindView(R.id.tvPoint)
	TextView tvPoint;
	@BindView(R.id.llCanclePoint)
	LinearLayout llCanclePoint;
	@BindView(R.id.tvCancelPoint)
	TextView tvCancelPoint;
	@BindView(R.id.state_system)
	Spinner state_system;
	@BindView(R.id.state_equip)
	Spinner state_equip;
	@BindView(R.id.state_build_no)
	Spinner state_build_no;
	@BindView(R.id.state_layout_no)
	Spinner state_layout_no;
	@BindView(R.id.etGroup)
	EditText etGroup;
	@BindView(R.id.etNo)
	EditText etNo;
	@BindView(R.id.etEquipName)
	EditText etEquipName;
	@BindView(R.id.etPosition)
	EditText etPosition;
	@BindView(R.id.tvX)
	TextView tvX;
	@BindView(R.id.tvY)
	TextView tvY;
	@BindView(R.id.tvBrand)
	TextView tvBrand;
	@BindView(R.id.tvModel)
	TextView tvModel;
	@BindView(R.id.state_equip_type)
	Spinner state_equip_type;
	@BindView(R.id.etPrice)
	EditText etPrice;
	@BindView(R.id.tvPost)
	TextView tvPost;
	@BindView(R.id.cvDetail)
	android.support.v7.widget.CardView cvDetail;
	@BindView(R.id.textview_status)
	TextView tvStatus;

	// 系统列表适配器
	CommonAdapter<EquipSystemBean> stateSystemAdapter;
	// 系统列表数据源
	List<EquipSystemBean> systemDataList = new ArrayList<EquipSystemBean>();
	// 系统-设备列表适配器
	CommonAdapter<SystemEquipItemBean> stateEquipItemAdapter;
	// 系统-设备列表数据源
	List<SystemEquipItemBean> systemEquipItemDataList = new ArrayList<SystemEquipItemBean>();

	// 大楼列表适配器
	CommonAdapter<BuildEquipBean> stateDlAdapter;
	// 大楼列表数据源
	List<BuildEquipBean> dlDataList = new ArrayList<BuildEquipBean>();
	// 楼层列表适配器
	CommonAdapter<FloorBean> stateLcAdapter;
	// 楼层列表数据源
	List<FloorBean> lcDataList = new ArrayList<FloorBean>();
	// 设备类型列表适配器
	CommonAdapter<EquipType> stateEquipTypeAdapter;
	// 设备类型列表数据源
	List<EquipType> equipTypeDataList = new ArrayList<EquipType>();

	PlanBean planBean;
	String companyId;

	Dialog dialog;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_equip_add);
		ButterKnife.bind(this);
		init();
	}

	private void init() {
		getIntentData();
		setTop();
		setEquipViewStatus();
		setAdapter();
		getDlData();
	}

	private void getIntentData() {
		companyId = getIntent().getStringExtra("companyId");
	}

	private void setTop() {
		tvTitle.setText("新增设备");
		tvSearch.setCompoundDrawables(null, null, null, null);
		tvSearch.setText("取消");
	}

	private void setEquipViewStatus() {
		ivPic.setmPhotoClickInterface(new PhotoClickInterface() {

			@Override
			public void onPhotoClcik(float x, float y, float xRatio,
					float yRatio) {
				tvX.setText(xRatio + "");
				tvY.setText(yRatio + "");
			}

			@Override
			public void onPointClick(String equipment_id, float x, float y,
					float xRatio, float yRatio) {
				// TODO Auto-generated method stub

			}
		});

		// 设置必填项目验证
		etGroup.setTag(R.id.tag_view_empty, "分组不能为空");
		etEquipName.setTag(R.id.tag_view_empty, "名称不能为空");
		etNo.setTag(R.id.tag_view_empty, "编码不能为空");
		etPrice.setTag(R.id.tag_view_empty, "单价不能为空");
		etPosition.setTag(R.id.tag_view_empty, "位置不能为空");
		state_system.setTag(R.id.tag_view_empty, "系统类别不能为空");
		state_equip.setTag(R.id.tag_view_empty, "系统设备类别不能为空");
		state_build_no.setTag(R.id.tag_view_empty, "大楼不能为空");
		state_layout_no.setTag(R.id.tag_view_empty, "楼层不能为空");
		state_equip_type.setTag(R.id.tag_view_empty, "设备类型不能为空");
		tvX.setTag(R.id.tag_view_empty, "请放置设备类型");
		tvY.setTag(R.id.tag_view_empty, "请放置设备类型");

		// 隐藏默认的平面图
		ivPic.setVisibility(View.GONE);
		rlPoint.setVisibility(View.GONE);
	}

	private void setAdapter() {

		resetSystem();
		stateSystemAdapter = new CommonAdapter<EquipSystemBean>(this, systemDataList,
				R.layout.item_state_small) {

			@Override
			public void convert(ViewHolder holder, EquipSystemBean t) {
				holder.setText(R.id.state_name, t.getInspection_name());
			}
		};
		state_system.setAdapter(stateSystemAdapter);
		state_system.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				EquipSystemBean build = (EquipSystemBean) parent.getAdapter()
						.getItem(position);
				state_system.setTag(R.id.tag_view_select_value, build.getInspection_id());
				resetSystemEquipItem();
				// 做个判断，如果上级菜单传给我们的是空id，即上级未选择选项，则我们不去获取下级的菜单
				if (!TextUtils.isEmpty(systemDataList.get(position).getInspection_id())) {
					getSystemEquipItemData(systemDataList.get(position).getInspection_id());
				}

			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {

			}
		});
		
		resetSystemEquipItem();
		stateEquipItemAdapter = new CommonAdapter<SystemEquipItemBean>(this, systemEquipItemDataList,
				R.layout.item_state_small) {

			@Override
			public void convert(ViewHolder holder, SystemEquipItemBean t) {
				holder.setText(R.id.state_name, t.getEquipment_name());
			}
		};
		state_equip.setAdapter(stateEquipItemAdapter);
		state_equip.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				SystemEquipItemBean systemEquipItemBean = (SystemEquipItemBean) parent.getAdapter().getItem(
						position);
				state_equip.setTag(R.id.tag_view_select_value,systemEquipItemBean.getEquipment_id());
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {

			}
		});
		
		
		
		resetBuild();
		stateDlAdapter = new CommonAdapter<BuildEquipBean>(this, dlDataList,
				R.layout.item_state_small) {

			@Override
			public void convert(ViewHolder holder, BuildEquipBean t) {
				holder.setText(R.id.state_name, t.getBuilding());
			}
		};
		state_build_no.setAdapter(stateDlAdapter);
		state_build_no.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				BuildEquipBean build = (BuildEquipBean) parent.getAdapter()
						.getItem(position);
				state_build_no.setTag(R.id.tag_view_select_value, build.getId());
				resetBuildLayout();
				// 做个判断，如果上级菜单传给我们的是空id，即上级未选择选项，则我们不去获取下级的菜单
				if (!TextUtils.isEmpty(dlDataList.get(position).getId())) {
					getLcData(dlDataList.get(position).getId());
				}

				// 隐藏平面图
				resetPoint(false);
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {

			}
		});

		resetBuildLayout();
		stateLcAdapter = new CommonAdapter<FloorBean>(this, lcDataList,
				R.layout.item_state_small) {

			@Override
			public void convert(ViewHolder holder, FloorBean t) {
				holder.setText(R.id.state_name, t.getFloor_no());
			}
		};
		state_layout_no.setAdapter(stateLcAdapter);
		state_layout_no.setOnItemSelectedListener(new OnItemSelectedListener() {

			@Override
			public void onItemSelected(AdapterView<?> parent, View view,
					int position, long id) {
				FloorBean floor = (FloorBean) parent.getAdapter().getItem(
						position);
				state_layout_no.setTag(R.id.tag_view_select_value,
						floor.getId());
				resetEquipType();
				// 做个判断，如果上级菜单传给我们的是空id，即上级未选择选项，则我们不去获取下级的菜单
				if (!TextUtils.isEmpty(lcDataList.get(position).getId())) {
					getLcDetail(lcDataList.get(position).getId());
				}
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {

			}
		});

		resetEquipType();

		stateEquipTypeAdapter = new CommonAdapter<EquipType>(this,
				equipTypeDataList, R.layout.item_state_small) {

			@Override
			public void convert(ViewHolder holder, EquipType t) {
				holder.setText(R.id.state_name, t.getIcon_name());
			}
		};
		state_equip_type.setAdapter(stateEquipTypeAdapter);
		state_equip_type
				.setOnItemSelectedListener(new OnItemSelectedListener() {

					@Override
					public void onItemSelected(AdapterView<?> parent,
							View view, int position, long id) {
						EquipType et = (EquipType) parent.getAdapter().getItem(
								position);
						state_equip_type.setTag(R.id.tag_view_select_value,
								et.getId());
						Glide.with(getContext()).load(et.getIcon_url())
								.asBitmap().into(new SimpleTarget<Bitmap>() {

									@Override
									public void onResourceReady(Bitmap bitmap,
											GlideAnimation glideAnimation) {
										ivPic.setWaterBitmap(bitmap);
									}
								});
					}

					@Override
					public void onNothingSelected(AdapterView<?> parent) {

					}
				});
	}

	/**   
	 * @author: HYM 
	 * @Title: getEquipSystemData   
	 * @Description: TODO(获取设备系统)    void 
	 * @date: 2017-10-24
	 */  
	private void getEquipSystemData() {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("company_id", companyId);

		VolleyRequest.StringRequestPost(this,
				WebApi.MAINTENANCE_OWNER_EQUIP_SYSTEM_LIST, "", params,
				new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								String data = obj.getString("data");
								List<EquipSystemBean> temp = new Gson()
										.fromJson(
												data,
												new TypeToken<List<EquipSystemBean>>() {
												}.getType());
								if (temp == null || temp.size() <= 0) {
									ToastUtil.getInstances().showMsg("请先新增系统类型");
								} else {
									resetSystem();
									systemDataList.addAll(temp);
									stateSystemAdapter.notifyDataSetChanged();
								}
							} else {
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
						}

					}

					@Override
					public void stringError(VolleyError error) {
					}
				});
	}
	
	private void getSystemEquipItemData(String id) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("inspection_id", id);

		VolleyRequest.StringRequestPost(this,
				WebApi.MAINTENANCE_OWNER_SYSTEM_EQUIP_ITEM_LIST, "", params,
				new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								String data = obj.getString("data");
								List<SystemEquipItemBean> temp = new Gson().fromJson(
										data, new TypeToken<List<SystemEquipItemBean>>() {
										}.getType());
								if (temp == null || temp.size() <= 0) {
									ToastUtil.getInstances().showMsg("请先新增系统设备类型");
								} else {
									resetSystemEquipItem();
									systemEquipItemDataList.addAll(temp);
									stateEquipItemAdapter.notifyDataSetChanged();
								}
							} else {
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
						}

					}

					@Override
					public void stringError(VolleyError error) {
					}
				});
	}
	
	private void getDlData() {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("company_id", companyId);

		VolleyRequest.StringRequestPost(this,
				WebApi.MAINTENANCE_OWNER_EQUIP_LIST, "", params,
				new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								String data = obj.getString("data");
								List<BuildEquipBean> temp = new Gson()
										.fromJson(
												data,
												new TypeToken<List<BuildEquipBean>>() {
												}.getType());
								if (temp == null || temp.size() <= 0) {
									ToastUtil.getInstances().showMsg("请先新增大楼");
								} else {
									resetBuild();
									dlDataList.addAll(temp);
									stateDlAdapter.notifyDataSetChanged();
								}
							} else {
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
						}

					}

					@Override
					public void stringError(VolleyError error) {
					}
				});
	}

	private void getLcData(String id) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("build_id", id);

		VolleyRequest.StringRequestPost(this,
				WebApi.MAINTENANCE_OWNER_BUILD_LAYOUT_LIST, "", params,
				new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								String data = obj.getString("data");
								List<FloorBean> temp = new Gson().fromJson(
										data, new TypeToken<List<FloorBean>>() {
										}.getType());
								if (temp == null || temp.size() <= 0) {
									ToastUtil.getInstances().showMsg("请先新增楼层");
								} else {
									resetBuildLayout();
									lcDataList.addAll(temp);
									stateLcAdapter.notifyDataSetChanged();
								}
							} else {
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
						}

					}

					@Override
					public void stringError(VolleyError error) {
					}
				});
	}

	private void getLcDetail(String floorId) {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("floor_id", floorId);

		VolleyRequest.StringRequestPost(getContext(),
				WebApi.MAINTENANCE_OWNER_FLOOR_INFO, "", params,
				new StringInterface(getContext()) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								String data = obj.getString("data");
								planBean = new Gson().fromJson(data,
										PlanBean.class);
								cvDetail.setVisibility(View.VISIBLE);
								resetPoint(true);
								Glide.with(getContext())
										.load(planBean.getMap())
										.asBitmap()
										// 加入了计算高度的方法
										.listener(
												new RequestListener<String, Bitmap>() {
													@Override
													public boolean onException(
															Exception e,
															String model,
															Target<Bitmap> target,
															boolean isFirstResource) {
														return false;
													}

													@Override
													public boolean onResourceReady(
															Bitmap resource,
															String model,
															Target<Bitmap> target,
															boolean isFromMemoryCache,
															boolean isFirstResource) {
														if (ivPic == null) {
															return false;
														}
														ViewGroup.LayoutParams params = ivPic
																.getLayoutParams();
														int vw = ivPic
																.getWidth()
																- ivPic.getPaddingLeft()
																- ivPic.getPaddingRight();
														Drawable drawable = new BitmapDrawable(
																resource);
														float scale = (float) vw
																/ (float) drawable
																		.getIntrinsicWidth();
														int vh = Math.round(drawable
																.getIntrinsicHeight()
																* scale);
														params.height = vh
																+ ivPic.getPaddingTop()
																+ ivPic.getPaddingBottom();
														ivPic.setLayoutParams(params);
														return false;
													}
												})
										.into(new SimpleTarget<Bitmap>(
												DeviceUtil.getInstance()
														.getScreenWidth() / 2,
												DeviceUtil.getInstance()
														.getScreenHeight() / 2) {

											@Override
											public void onResourceReady(
													Bitmap bitmap,
													GlideAnimation glideAnimation) {
												ivPic.setImageBitmap(bitmap);
												ivPic.setBmp(bitmap);
												setMaps(planBean.getEquipList());
											}

											public void onLoadFailed(
													Exception e,
													Drawable errorDrawable) {
												ivPic.setImageBitmap(null);
												ivPic.setBmp(null);
												ToastUtil.getInstances()
														.showMsg("图片加载失败，请重试");
											};
										});
								// 获取设备类型
								getEquipType();
								//获取设备系统
								resetSystem();
								getEquipSystemData();
								// 设置品牌、规格
								tvBrand.setText(planBean.getEquipment_brand());
								tvModel.setText(planBean.getEquipment_model());
							} else {
								ToastUtil.getInstances().showMsg(info);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
						}
					}

					@Override
					public void stringError(VolleyError error) {
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}
	
	/**   
	 * @author: HYM 
	 * @Title: resetSystem   
	 * @Description: TODO(重置设备系统列表的数据)    void 
	 * @date: 2017-10-24
	 */  
	private void resetSystem() {
		systemDataList.clear();
		EquipSystemBean equipSystemBean = new EquipSystemBean();
		equipSystemBean.setInspection_id("");
		equipSystemBean.setInspection_name("请选择");
		systemDataList.add(equipSystemBean);
		if (stateSystemAdapter != null) {
			stateSystemAdapter.notifyDataSetChanged();
		}
	}
	
	/**   
	 * @author: HYM 
	 * @Title: resetSystem   
	 * @Description: TODO(重置系统-设备列表的数据)    void 
	 * @date: 2017-10-24
	 */  
	private void resetSystemEquipItem() {
		systemEquipItemDataList.clear();
		SystemEquipItemBean systemEquipItemBean = new SystemEquipItemBean();
		systemEquipItemBean.setEquipment_id("");
		systemEquipItemBean.setEquipment_name("请选择");
		systemEquipItemDataList.add(systemEquipItemBean);
		if (stateEquipItemAdapter != null) {
			stateEquipItemAdapter.notifyDataSetChanged();
		}
	}

	/**
	 * @author: HYM
	 * @Title: resetBuild
	 * @Description: TODO(重置大楼数据) void
	 * @date: 2017-5-16
	 */
	private void resetBuild() {
		dlDataList.clear();
		BuildEquipBean dl = new BuildEquipBean();
		dl.setId("");
		dl.setBuilding("请选择");
		dlDataList.add(dl);
	}

	/**
	 * @author: HYM
	 * @Title: resetBuildLayout
	 * @Description: TODO(重置楼层数据) void
	 * @date: 2017-5-16
	 */
	private void resetBuildLayout() {
		// 隐藏详情和平面图
		cvDetail.setVisibility(View.GONE);
		resetPoint(false);

		lcDataList.clear();
		FloorBean lc = new FloorBean();
		lc.setId("");
		lc.setFloor_no("请选择");
		lcDataList.add(lc);
		if (stateLcAdapter != null) {
			stateLcAdapter.notifyDataSetChanged();
		}

	}

	void getEquipType() {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());

		VolleyRequest.StringRequestPost(getContext(),
				WebApi.MAINTENANCE_OWNER_EQUIP_TYPE, "", params,
				new StringInterface(getContext()) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								String data = obj.getString("data");
								List<EquipType> temp = new Gson().fromJson(
										data, new TypeToken<List<EquipType>>() {
										}.getType());
								setEquipType(temp);
							} else {
								ToastUtil.getInstances().showMsg(info);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
						}
					}

					@Override
					public void stringError(VolleyError error) {
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	private void resetEquipType() {
		equipTypeDataList.clear();
		EquipType et = new EquipType();
		et.setId("");
		et.setIcon_name("请选择");
		et.setIcon_url("");
		equipTypeDataList.add(et);
		if (stateEquipTypeAdapter != null) {
			stateEquipTypeAdapter.notifyDataSetChanged();
		}
	}

	void setEquipType(List<EquipType> list) {
		resetEquipType();
		if (list != null && list.size() > 0) {
			equipTypeDataList.addAll(list);
			stateEquipTypeAdapter.notifyDataSetChanged();
		}
	}

	void setMaps(final List<PlanEquip> goodsMaps) {
		for (int i = 0; i < goodsMaps.size(); i++) {
			final int temp = i;
			Glide.with(this.getContext()).load(goodsMaps.get(i).getIcon())
					.asBitmap().into(new SimpleTarget<Bitmap>() {
						@Override
						public void onResourceReady(Bitmap bitmap,
								GlideAnimation glideAnimation) {
							int color=R.color.half_half_half_transparency;
							ivPic.loadWaterList(bitmap, goodsMaps.get(temp)
									.getX_axis(), goodsMaps.get(temp)
									.getY_axis(), false,color,255);
						}
					}); // 方法中设置asBitmap可以设置回调类型
		}
	}

	Context getContext() {
		return this;
	}

	@OnClick({ R.id.tvBack, R.id.tvSearch, R.id.tvPost, R.id.tvPoint,
			R.id.tvCancelPoint })
	public void onClick(View view) {
		switch (view.getId()) {
		case R.id.tvBack:
		case R.id.tvSearch:
			finish();
			break;
		case R.id.tvPost:
			if (CheckUtil.checkView(etGroup,state_system,state_equip,state_build_no, state_layout_no, etNo,
					etEquipName, etPosition, tvX, tvY, state_equip_type,
					etPrice)) {
				addEquip();
			}
			break;
		case R.id.tvPoint:
			view.setVisibility(View.GONE);
			llCanclePoint.setVisibility(View.VISIBLE);
			ivPic.setClick_status(1);
			break;
		case R.id.tvCancelPoint:
			llCanclePoint.setVisibility(View.GONE);
			tvPoint.setVisibility(View.VISIBLE);
			ivPic.setClick_status(0);
			break;
		default:
			break;
		}
	}

	void addEquip() {
		Map<String, String> params = new HashMap<String, String>();
		params.put(AppConfig.ACCESS_TOKEN,
				UserInfoUtil.getCurrentUserAccessToken());
		params.put("company_id", planBean.getCompany_id());
		params.put(
				"build_id",
				new Gson().fromJson(
						state_build_no.getSelectedItem().toString(),
						BuildEquipBean.class).getId());
		params.put(
				"floor_id",
				new Gson().fromJson(
						state_layout_no.getSelectedItem().toString(),
						FloorBean.class).getId());
		params.put("goodsProduct", tvBrand.getText().toString());
		params.put("goodsType", tvModel.getText().toString());
		params.put(
				"equipType",
				new Gson().fromJson(
						state_equip_type.getSelectedItem().toString(),
						EquipType.class).getId());
		params.put("bh_code", etNo.getText().toString());
		params.put("goodsName", etEquipName.getText().toString());
		params.put("goodsPrice", etPrice.getText().toString());
		params.put("place", etPosition.getText().toString());
		params.put("x_axis", tvX.getText().toString());
		params.put("y_axis", tvY.getText().toString());
		params.put("inspection_id", new Gson().fromJson(
				state_system.getSelectedItem().toString(),
				EquipSystemBean.class).getInspection_id());
		params.put("equipment_id", new Gson().fromJson(
				state_equip.getSelectedItem().toString(),
				SystemEquipItemBean.class).getEquipment_id());
		params.put("groupno", etGroup.getText().toString());

		dialog = showDialog(dialog);
		VolleyRequest.StringRequestPost(this, WebApi.MAINTENANCE_OWNER_EQUIP_ADD, "",
				params, new StringInterface(this) {

					@Override
					public void stringSuccess(String result) {
						try {
							JSONObject obj = new JSONObject(result);
							String status = obj.getString("status");
							String info = obj.getString("info");
							if (status.equals("200")) {
								ToastUtil.getInstances().showMsg(info);
								finish();
							} else if (status.equals("404")
									&& info.contains("尚未登录")) {
								ToastUtil.getInstances().showMsg(
										"尚未登录或该用户在其他地方登录，请重新登录！");
								// 清除环信登录
								UserHelp.getInstance().clearUser(
										AppBase.Context, true);
								return;
							} else {
								ToastUtil.getInstances().showMsg(info);
							}
						} catch (JSONException e) {
							e.printStackTrace();
						} finally {
							hideDialog(dialog);
						}

					}

					@Override
					public void stringError(VolleyError error) {
						hideDialog(dialog);
						ToastUtil.getInstances().showMsg(
								R.string.err_http_response);
					}
				});
	}

	void resetPoint(boolean isShow) {
		llCanclePoint.setVisibility(View.GONE);
		tvPoint.setVisibility(View.VISIBLE);
		ivPic.setClick_status(0);
		if (isShow) {
			rlPoint.setVisibility(View.VISIBLE);
			ivPic.setVisibility(View.VISIBLE);
		} else {
			rlPoint.setVisibility(View.GONE);
			ivPic.setVisibility(View.GONE);
		}
	}
}
